package cn.zhizihua.controller;


import cn.zhizihua.pojo.Menu;
import cn.zhizihua.query.MenuQuery;
import cn.zhizihua.service.IMenuService;
import cn.zhizihua.vo.ResultBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhizihua
 * @since 2024-12-19
 */
//在controller中写一个对应的接口
@RestController
@RequestMapping("/menu")
@Api(tags = "菜单管理")
public class MenuController extends BaseController<Menu, MenuQuery>{

    @Autowired
    IMenuService menuService;

    @ApiOperation(value = "查询树结构菜单-联查" )
    @PostMapping("/tree")
    public ResultBean treeMenu(@RequestBody MenuQuery menuQuery){
        List<Menu> tree = menuService.tree(menuQuery.getJoinWrapper());
        return ResultBean.SUCCESS(tree);
    }

    @ApiOperation(value = "查询一级菜单" )
    @GetMapping("/level1")
    public ResultBean firstLevelMenu(){
        QueryWrapper<Menu> queryWrapper = new QueryWrapper<>();
        queryWrapper.isNull("parent_id");
        List<Menu> tree = menuService.list(queryWrapper);
        return ResultBean.SUCCESS(tree);
    }

    @ApiOperation(value = "查询所有菜单-单表" )
    @GetMapping("/all/tree")
    public ResultBean all(){
        List<Menu> tree = menuService.tree(null);
        return ResultBean.SUCCESS(tree);
    }

}